<%@ page pageEncoding="utf-8" isELIgnored="false" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>校园超市管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/css/public.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/css/style.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/js/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/icon.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/js/bootstrap/css/bootstrap.min.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jsp/js/jQuery1.11.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery.easyui.min.js"></script>
    <%--  <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.pagination.js"></script>--%>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        jQuery.noConflict();
        var  loginOut;
        var shanchu;
        var xiugai;
        var showMessage;
        jQuery(function ($) {
            showMessage = function (error) {
                console.log(error);
                if (error.message.indexOf("403") != -1){
                    this.$message.error("对不起，您无权访问");
                }else{
                    this.$message.error("未知错误");
                }
            },
            xiugai = function xiugaiProduct() {
                var i = $("#checkboxs:checked").length;
                if (i > 1) {
                    $.messager.alert("温馨提示", "只能选择一项", "error");
                } else if (i < 1) {
                    $.messager.alert("温馨提示", "请选择一项", "error");
                } else {
                    location.href = "${pageContext.request.contextPath}/product/findById?id=" + $("#checkboxs:checked").val();
                }
            },
            shanchu = function shanchuProduct() {
                var check = $("#checkboxs:checked").length;
                var ids = "";
                if (check == 0) {
                    $.messager.alert("温馨提示", "请选择要删除的选项", "question");
                } else {
                    $.messager.confirm("温馨提示", "确定要删除吗？", function (r) {
                        if (r) {
                            var checkboxs = $("#checkboxs:checked");
                            for (var i = 0; i < checkboxs.length; i++) {
                                ids += checkboxs[i].value + ',';
                            }
                            $.ajax({
                                url: "${pageContext.request.contextPath}/product/deleteProduct",
                                type: "post",
                                data: {"str": ids},
                                success: function (data) {
                                    //alert(data);
                                    if (data.data == "true") {
                                        var win = $.messager.progress({
                                            title: '温馨提示',
                                            msg: '正在删除...'
                                        });
                                        setTimeout(function () {
                                            $.messager.progress('close');
                                            $.messager.show({
                                                title: '温馨提示',
                                                msg: '删除成功',
                                                showType: 'show'
                                            });
                                        }, 3200);
                                        setTimeout(function () {
                                            location.href = "${pageContext.request.contextPath}/product/showProductList";
                                        }, 4700);
                                    } else {
                                        $.messager.show({
                                            title: '温馨提示',
                                            msg: '删除失败！',
                                            timeout: 0,
                                            showType: 'slide'
                                        });
                                        return false;
                                    }
                                },
                                statusCode: {
                                    403: function() {
                                        $.messager.show({
                                            title: '温馨提示',
                                            msg: '对不起,您无权访问此操作',
                                            timeout: 0,
                                            showType: 'slide'
                                        });
                                        //window.location.href = "login.html";
                                    }
                                }
                            })
                        } else {
                            return false;
                        }

                    });
                }
            }
            $.ajax({
                url: "${pageContext.request.contextPath}/proList",
                type: "post",
                datatype: "json",
                success: function (data) {
                    $.each(data.data, function (i, dom) {
                        $("#tigong").append("<option value=" + dom.id + ">" + dom.proName + "</option>");
                    })
                }
            });
            //获取输入框商品名字和供应商名字进行模糊查询
            var selectProductName;
            var selectProvider;
            $("#btn").click(function () {
                selectProductName = $("#selectProductName").val();
                selectProvider=$("#tigong option:selected").val();
                load(0, 5);
            });
            load(0, 5);
            function load(index, PageSize) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/product/findAll",
                    type: "post",
                    data: {"PageIndex": index, "PageSize": PageSize, "selectProductName": selectProductName,"selectProvider":selectProvider},
                    success: function (data) {
                        //模拟ajax去后端读取页数，获取数据并渲染列表的过程
                        $('#productLists').html('');
                        $.each(data.data.list, function (i, item) {
                            $("#productLists").append("<tr><td><input name='checkboxs' type='checkbox' id='checkboxs' value=" + item.id + "></td><td>" + item.code + "</td><td>" + item.name +
                                "</td><td>" + item.price + "</td><td>" + item.spec + "</td><td>" + item.message + "</td><td>" + item.provider.proName + "</td></td>");
                        });
                        //渲染分
                        if (data.data.totalRecords > 0) {
                            $('#pagination').pagination({
                                total: data.data.totalRecords,//总记录数
                                pageSize: PageSize,//页面大小
                                pageNumber: index + 1,//当前页码
                                pageList: [5, 10, 15], //5表示页显示5条数据。
                                onSelectPage: function (pageNumber, PageSize) {
                                    load(pageNumber - 1, PageSize);
                                }
                            });

                        } else {
                            $('#pagination').html("<span style='color:red;font-size: 18px'>没有检索到结果~~~~~！！！！！！</span>");
                        }
                    }
                });
            }

            loginOut=function userLoginOut() {
                $.messager.confirm("温馨提示", "确定要退出吗？", function (r) {
                    if (r) {
                        location.href="${pageContext.request.contextPath}/loginout";
                    } else {
                        return false;
                    }

                });
            }

        });
    </script>
</head>
<body>
<!--头部-->
<header class="publicHeader">
    <h1>校园超市管理系统</h1>
    <div class="publicHeaderR">
        <p><span>您好！</span><span style="color: #fff21b">${keyword} ${login}</span> , 欢迎你！</p>
        <%--<a href="login.html">退出</a>--%>
    </div>
</header>
<!--时间-->
<section class="publicTime">
    <span id="time">2015年1月1日 11:11  星期一</span>
    <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
</section>
<!--主体内容-->
<section class="publicMian ">
    <div class="left">
        <h2 class="leftH2">
            <span class="span_gn">功能列表</span>
        </h2>
        <nav>
            <ul class="list">
                <li id="active"><a href="${pageContext.request.contextPath}/jsp/productList.jsp">商品管理</a></li>
                <li ><a href="${pageContext.request.contextPath}/jsp/billList.jsp">订单管理</a></li>
                <li><a href="${pageContext.request.contextPath}/jsp/providerList.jsp">供应商管理</a></li>
                <li><a href="${pageContext.request.contextPath}/jsp/userList.jsp">用户管理</a></li>
                <li><a href="${pageContext.request.contextPath}/jsp/password.jsp">密码修改</a></li>
                <li><a onclick="loginOut()">退出系统</a></li>
            </ul>
        </nav>
    </div>
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>商品管理页面</span>
        </div>
        <div class="search">
            <span>商品名称：</span>
            <input id="selectProductName" type="text" placeholder="请输入商品的名称"/>

            <span>供应商：</span>
            <select name="tigong" id="tigong">
                <option value="0">--请选择--</option>

            </select>


            <input id="btn" type="button" value="查询"/>
        </div>
        <div class="searchText">
                <a href="${pageContext.request.contextPath}/jsp/productAdd.jsp">添加商品</a>
                <a onclick="return xiugai()">修改商品</a>
                <a onclick="return shanchu()">删除商品</a>
                <a href="${pageContext.request.contextPath}/product/daochu ">导出商品</a>
                <a href="${pageContext.request.contextPath}/jsp/productechart.jsp ">数据展示</a>
         </div>

        <!--账单表格 样式和供应商公用-->
        <table class="providerTable" cellpadding="0" cellspacing="0">
            <tr class="firstTr">
                <th width="7%">请选择</th>
                <th width="7%">商品编码</th>
                <th width="20%">商品名称</th>
                <th width="10%">商品价格</th>
                <th width="10%">商品容量</th>
                <th width="10%">商品信息码</th>
                <th width="10%">供应商</th>
            </tr>
            <tbody id="productLists"></tbody>
        </table>
        <div class="pagination" id="pagination" style="margin:4px 0 0 0"></div>
    </div>
</section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeBi">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该订单吗？</p>
            <a href="#" id="yes">确定</a>
            <a href="#" id="no">取消</a>
        </div>
    </div>
</div>
    <footer class="footer">
        版权归本超市所有
    </footer>


<script src="${pageContext.request.contextPath}/jsp/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/jsp/js/js.js"></script>
<script src="${pageContext.request.contextPath}/jsp/js/time.js"></script>

</body>
</html>